﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Auditing;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Entities.Auditing;
using WisDom.SmartTMS.Enums;

namespace WisDom.SmartTMS.Entity
{
    /// <summary>
    /// 审批日志实体
    /// </summary>
    public class AuditLog : CreationAuditedEntity<Guid>
    {
        /// <summary>
        /// 审核主记录ID
        /// </summary>
        public Guid? AuditId { get; private set; }

        /// <summary>
        /// 审核人ID
        /// </summary>
        public Guid? ProcessPersonId { get; private set; }

        /// <summary>
        /// 审核人姓名
        /// </summary>
        public string ProcessPersonName { get; private set; }

        /// <summary>
        /// 审核结果
        /// </summary>
        public AuditState ProcessResult { get; private set; }

        /// <summary>
        /// 审核时间
        /// </summary>
        public DateTime? AuditTime { get; private set; }

        /// <summary>
        /// 审核备注信息
        /// </summary>
        public string Remark { get; private set; }

        protected AuditLog()
        {

        }

        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="logId"></param>
        /// <param name="auditId"></param>
        /// <param name="processPersonId"></param>
        /// <param name="processPersonName"></param>
        /// <param name="isDepBoss"></param>
        public AuditLog(Guid logId, Guid auditId, Guid processPersonId, string processPersonName)
        {
            Id = logId;                            //主键
            AuditId = auditId;                     //审核主记录Id
            ProcessPersonId = processPersonId;     //审核人Id
            ProcessPersonName = processPersonName; //审核人姓名
            Remark = string.Empty;                 //备注默认为空
            ProcessResult = AuditState.ToAudit;    //审核结果默认为待审核
            AuditTime = null;                      //审核时间默认为空
            CreationTime = DateTime.Now;           //创建时间
        }

        /// <summary>
        /// 修改审计日志
        /// </summary>
        /// <param name="state">审批结果</param>
        /// <param name="remark">审批备注</param>
        public void UpdateAuditLog(AuditState state, string remark)
        {
            ProcessResult = state;    //审核结果
            Remark = Check.NotNullOrWhiteSpace(remark, nameof(remark)); //审核备注(不能为空）
            AuditTime = DateTime.Now; //审核时间

        }
    }
}
